package com.czz.ucenter.controller;

import com.czz.common.exception.ResultCodeEnum;
import com.czz.common.vo.R;
import com.czz.ucenter.entity.Audit;
import com.czz.ucenter.service.AuditService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName: AuditController
 * @Author Czz
 * @Date 2020/2/21
 * @Time 16:01
 **/
@RestController
@RequestMapping(value = "/user/audits")
public class AuditController {

    @Autowired
    AuditService auditService;

    /**
    * @Description 根据用户id查询讲师申请信息
    * @Param [userId]
    * @Return com.czz.common.vo.R
    * @Author Czz
    * @Date 2020/2/21
    * @Time 16:04
    **/
    @GetMapping(value = "/{userId}")
    public R getAuditByUserId(@PathVariable String userId){
        if (StringUtils.isEmpty(userId)){
            return R.setResult(ResultCodeEnum.INPUT_ERROR);
        }
        Audit audit = auditService.getAuditByUserId(userId);
        return R.ok().data("item",audit);
    }

    /**
    * @Description 新增讲师申请
    * @Param [audit]
    * @Return com.czz.common.vo.R
    * @Author Czz
    * @Date 2020/2/21
    * @Time 16:08
    **/
    @PostMapping(value = "")
    public R saveAudit(Audit audit){
        if (StringUtils.isEmpty(audit.getUserId()) || StringUtils.isEmpty(audit.getCareer()) || StringUtils.isEmpty(audit.getIntro()) || StringUtils.isEmpty(audit.getName())){
            return R.setResult(ResultCodeEnum.INPUT_ERROR);
        }
        auditService.save(audit);
        return R.ok();
    }

    /**
    * @Description 更新讲师申请
    * @Param [audit]
    * @Return com.czz.common.vo.R
    * @Author Czz
    * @Date 2020/3/18
    * @Time 11:26
    **/
    @PutMapping(value = "")
    public R updateAudit(Audit audit){
        if (StringUtils.isEmpty(audit.getAuditId()) || ObjectUtils.isEmpty(audit)){
            return R.setResult(ResultCodeEnum.INPUT_ERROR);
        }
        auditService.updateAudit(audit);
        return R.ok();
    }
}
